package com.kcn.xml;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;

public class excel2sql {
	public static void main(String arg[]) {
		File fl = new File("D:\\淄博武汉太原客户信息.xls");
		System.out.println(fl.getName());
		Workbook wb = null;
		try {
			wb = Workbook.getWorkbook(fl);
		} catch (BiffException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		Sheet st = wb.getSheet(0);
		String s="";
		System.out.println(st.getRows());
		for (int i = 1; i < 51; i++) {
			Cell[] c = st.getRow(i);
			StringBuffer sb = new StringBuffer();
			String fg = "','";
			String line=sb.append("insert into Customer values(").append(i).append(",'").append(c[0].getContents()).append(fg)
					.append(c[1].getContents()).append(fg).append(c[2].getContents()).append(fg)
					.append(c[3].getContents()).append(fg).append(c[4].getContents()).append(fg)
					.append(c[5].getContents()).append(fg).append(c[6].getContents()).append("');").append("\n").toString();
			s+=line;
			
		}
		wb.close();
		try {
			FileOutputStream fo=new FileOutputStream("D:\\cussql.txt");
			OutputStreamWriter ow=new OutputStreamWriter(fo,"UTF-8");
			try {
				System.out.print(s);
				ow.write(s);
				ow.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
}
